package top.atluofu.luofuecommerce.order.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.atluofu.luofuecommerce.order.entity.OrderEntity;
import top.atluofu.luofuecommerce.order.entity.OrderReturnApplyEntity;

import java.util.Date;
import java.util.UUID;

/**
 * @ClassName: RabbitController
 * @description: TODO
 * @author: 有罗敷的马同学
 * @datetime: 2022Year-11Month-24Day-22:40
 * @Version: 1.0
 */
@Slf4j
@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "num",defaultValue = "10") Integer num){
        for (int i = 0; i < num; i++) {
            if (i%2 == 0) {
                OrderReturnApplyEntity orderReturnApplyEntity = new OrderReturnApplyEntity();
                orderReturnApplyEntity.setId(1L);
                orderReturnApplyEntity.setCreateTime(new Date());
                orderReturnApplyEntity.setReturnName("哈哈哈");
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", orderReturnApplyEntity);
            } else {
                OrderEntity entity = new OrderEntity();
                entity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", entity);
            }
        }
        return "ok";
    }
}
